class Solution:
    def maxValue(self, grid: List[List[int]]) -> int:
        last = [0]*len(grid[0]) # 第一行
        for i in range(len(grid)):
            for j in range(len(grid[0])):
                if j :
                    last[j] = max(grid[i][j] + last[j], grid[i][j] + last[j-1]) # 动态规划
                else :
                    last[j] = grid[i][j] + last[j]    # 第一列
        return last[-1]